package com.power.util;

import com.power.model.SecurityUser;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Set;

/**
 * @Description 认证授权工具类
 * @Author dingchunlin
 * @Date 2024/07/12 16:49
 * @Version 1.0.0
 */
public class AuthUtils {

    /**
     * 获取当前登录用户信息
     * @return SecurityUser
     */
    public static SecurityUser getSecurityUser(){
        SecurityUser securityUser = (SecurityUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return securityUser;
    }

    /**
     * 获取当前登录用户ID
     * @return Long
     */
    public static Long getUserId(){
        SecurityUser securityUser = getSecurityUser();
        return securityUser.getUserId();
    }

    /**
     * 获取当前登录用户操作权限
     * @return Set<String>
     */
    public static Set<String> getLoginUserPerms(){
        SecurityUser securityUser = getSecurityUser();
        return securityUser.getPerms();
    }

    /**
     * 获取当前登录用户的微信openid
     * @return String
     */
    public static String getMemberOpenId(){
       return getSecurityUser().getOpenid();
    }
}
